package com.ewing.common.exception;

import com.ewing.common.constants.AjaxRespCode;
import com.ewing.common.constants.ResponseCode;


/**
 * 业务错误异常。
 */
public class BusinessException extends RuntimeException {
  /**
   * 
   * created by Joeson on 2016年4月24日 下午4:49:22
   */
  private static final long serialVersionUID = 1L;
  /**
   * 业务CODE码，详情见 {@link common.constants.uc.common.constants.open.base.ResponseCode}。
   */
  private int code;

  public BusinessException() {
    super();
    setErrorCode(ResponseCode.UNKOWN_ERROR);
  }


  public BusinessException(Throwable cause) {
    super(cause);
    setErrorCode(ResponseCode.UNKOWN_ERROR);
  }

  public BusinessException(String msg, Throwable cause) {
    super(msg, cause);
    setErrorCode(ResponseCode.UNKOWN_ERROR);
  }

  public BusinessException(Throwable cause, int errorCode) {
    super(cause);
    setErrorCode(errorCode);
  }

  public BusinessException(int errorCode, String message) {
    super(message);
    setErrorCode(errorCode);
  }

  public BusinessException(AjaxRespCode code) {
    super(code.message);
    setErrorCode(code.code);
  }


  public BusinessException(int errorCode, String message, Object... args) {
    super(String.format(message, args));
    setErrorCode(errorCode);
  }

  public int getErrorCode() {
    return code;
  }

  public void setErrorCode(int errorCode) {
    this.code = errorCode;
  }

}
